/*
 * @Date: 2023-08-11 09:20:04
 * @LastEditors: lyx
 * @LastEditTime: 2023-08-11 13:11:45
 * @FilePath: \sup-mini-app\src\components\Post\index.tsx
 * @Description:
 */
import React from "react";
import { View, Image } from "@tarojs/components";
import { AtCard } from "taro-ui";
import dayjs from "dayjs";
import "./index.scss";
import broadcastPng from "@/assets/post/broadcast.png";
import flowPng from "@/assets/post/flow.png";
import UsePost from "./hooks/usePost";

function Post(props: IPostProps) {
  const { list = [] } = props;
  const { handleClick } = UsePost();
  return (
    <View className="post-wrapper">
      {list.map((item: IPostItem) => (
        <View key={item?._id} className="post-item">
          <AtCard
            onClick={() => {
              handleClick(item?._id);
            }}
            note={`${item?.createBy ?? ""}  ${dayjs(item?.createdAt).format(
              "YYYY-MM-DD HH:mm:ss"
            )}`}
            // extra={dayjs(item?.createdAt).format("YYYY-MM-DD HH:mm:ss")}
            title={item?.title}
            thumb={item?.type === "flow" ? flowPng : broadcastPng}
          >
            <View className="post-item-intro">{item?.intro}</View>

            {item?.coverImage && (
              <View className="post-item-coverImage">
                <Image
                  mode="widthFix"
                  src={item?.coverImage}
                  className="post-item-image"
                />
              </View>
            )}
          </AtCard>
        </View>
      ))}
    </View>
  );
}

export default Post;
